/*
 * Copyright 2019 Flipkart Internet Pvt. Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flipkart.ohos.proteus;

import ohos.agp.components.Component;

import com.flipkart.ohos.proteus.value.Layout;
import com.flipkart.ohos.proteus.value.ObjectValue;

/**
 * ProteusView
 *
 * @author adtityasharat
 */
public interface ProteusView {
    /**
     * getViewManager
     *
     * @return The View Manager of this Proteus View.
     */
    Manager getViewManager();

    /**
     * setViewManager
     *
     * @param manager Sets a View Manager on this View.
     */
    void setViewManager(Manager manager);

    /**
     * getAsView
     *
     * @return The interface as an native View.
     */
    Component getAsView();

    /**
     * Manager
     *
     * @author aditya.sharat
     */
    interface Manager {
        /**
         * Update the {@link Component} with new data.
         *
         * @param data New data for the view
         */
        void update(ObjectValue data);

        /**
         * Look for a child view with the given id.  If this view has the given
         * id, return this view. Similar to {@link Component#findComponentById(int)} (int)}. Since
         * Proteus is a runtime inflater, layouts use String ids instead of int and it
         * generates unique int ids using the {@link IdGenerator}.
         *
         * @param id The  string id to search for.
         * @return The view that has the given id in the hierarchy or null
         */
        Component findViewById(String id);

        /**
         * getContext
         *
         * @return The Proteus Context associated with this Manager.
         */
        ProteusContext getContext();

        /**
         * getLayout
         *
         * @return The Layout of View which is hosting this manager.
         */
        Layout getLayout();

        /**
         * getDataContext
         *
         * @return The Data Context of the view which is hosting this manager.
         */
        DataContext getDataContext();

        /**
         * Returns this proteus view's extras.
         *
         * @return the Object stored in this view as a extra, or {@code null} if not set
         * @see #setExtras(Object)
         */

        Object getExtras();

        /**
         * Sets the extra associated with this view. A extra can be used to mark a view in its hierarchy
         * and does not have to be unique within the hierarchy. Extras can also be used to store data
         * within a proteus view without resorting to another data structure.
         * It is similar to {@link Component#setTag(Object)}
         *
         * @param extras The object to set as the extra.
         * @see #setExtras(Object)
         */
        void setExtras(Object extras);
    }
}
